#For Manuscript ID: FPA-24-Jul-0152.R2

#Title: Assessing the Effects of International Sanctions on Conflict-Induced Refugee Flows

#Author: Jerry Urtuzuastigui, Naji Bsisu, Kate Vernallis

#Email: gurtuzua@iu.edu

#R version 1.3.1073 (2020)

##############################
#######Relevant Packages######
##############################
library(lmtest)
library(lfe)
library(stargazer)
library(plm)
library(foreign)
library(AER)
library(MASS)
library(mediation)
library(dplyr)
library(tidyr)
library(tidyverse)
setwd("/Users/jerryurtz89/downloads")
load("FPA.Rdata")

################
################
################
###All Actors###
################
################
################

#############################
###Model 1: Mediator Model###
#############################
med.fit <- lm(lnvacTplus1 ~ 
                Military_Sanctions+Non_military_Sanctions_N.D.+v2x_api+lnTotal+
                lngdppc+ logpop+gd_ptsa
              , data=omit)
coeftest(med.fit, vcov.=NeweyWest(med.fit, adjust=TRUE, verbose=TRUE)) 

############################
###Model 2: Outcome Model###
############################
out.fit <- lm(logrefugeeTplus1 ~ 
                Military_Sanctions+Non_military_Sanctions_N.D.+v2x_api+lnvacTplus1+lnTotal+
                lngdppc + logpop+inter+gd_ptsa
              , data=omit)
coeftest(out.fit, vcov.=NeweyWest(out.fit, adjust=TRUE, verbose=TRUE)) 

#################################################
###Model 3: Military Sanctions Mediation Model###
#################################################
set.seed(23456)
med.out2 <- mediate(med.fit, out.fit, treat = "Military_Sanctions", mediator = "lnvacTplus1",
                    NeweyWest= TRUE, sims = 1000, dropobs = TRUE, conf.level=0.95)
summary(med.out2)

#Exponentiated Coefficient 
1-exp(-0.225)

#by reducing violence against civilians caused by armed actors, an imposed military sanction 
#corresponds to a decrease in the flow of refugees by about 20 percent. 

##################################################
###Figure 1: Military Sanctions Mediation Model###
##################################################
plot(med.out2, xlab="Effect size",main="Military Sanctions, 
     Violence Against Civilians, and Refugee Flows")
dev.off()

#################################################
###Model 4: Economic Sanctions Mediation Model###
#################################################
set.seed(23456)
med.out1 <- mediate(med.fit, out.fit, treat = "Non_military_Sanctions_N.D.", mediator = "lnvacTplus1",
                    NeweyWest= TRUE, sims = 1000, dropobs = TRUE, conf.level=0.95)
summary(med.out1)

#Exponentiated Coefficient
exp(0.2178)

#by increasing armed actors’ use of violence against civilians, an imposed economic sanction 
#corresponds to an increase in refugee flows by an average of 24 percent

##################################################
###Figure 1: Economic Sanctions Mediation Model###
##################################################
plot(med.out1, xlab="Effect size",main="Economic Sanctions, 
     Violence Against Civilians, and Refugee Flows")
dev.off()





##############################
##############################
##############################
###Sanctions Against Rebels###
##############################
##############################
##############################

#######################################
###REBEL Mediator and Outcome Models###
#######################################
#Rebel Economic Sanctions
rm(list=ls())
load("FPA.Rdata")

#Mediator Model: Sanctions against rebels
med.fit <- lm(lnvacTplus1 ~ 
                Military_Sanctions_Rebel+Non_military_Sanctions_N.D._Rebel+v2x_api+lnTotal+
                lngdppc + logpop+gd_ptsa
              , data=omit)
coeftest(med.fit, vcov.=NeweyWest(med.fit, adjust=TRUE, verbose=TRUE)) 

#Outcome Model: Sanctions against rebels
out.fit <- lm(logrefugeeTplus1 ~ 
                Military_Sanctions_Rebel+Non_military_Sanctions_N.D._Rebel+v2x_api+lnvacTplus1+lnTotal+
                lngdppc + logpop+inter+gd_ptsa
              , data=omit)
coeftest(out.fit, vcov.=NeweyWest(out.fit, adjust=TRUE, verbose=TRUE)) 

################################################################
###Model 5: Military Sanctions Against Rebels Mediation Model###
################################################################
set.seed(23456)
med.out4 <- mediate(med.fit, out.fit, treat = "Military_Sanctions_Rebel", mediator = "lnvacTplus1",
                    NeweyWest= TRUE, sims = 1000, dropobs = TRUE, conf.level=0.95)
summary(med.out4)

#Exponentiated Coefficient
1-exp(-0.212)

#by reducing violence against civilians caused by armed actors, an imposed military sanction against rebels
#corresponds to a decrease in the flow of refugees by about 19 percent. 

##################################################
###Figure 2: Military Sanctions Mediation Model###
##################################################
plot(med.out4, xlab="Effect size",main="Military Sanctions Against Rebels, 
     Violence Against Civilians, and Refugee Flows")
dev.off()

################################################################
###Model 6: Economic Sanctions Against Rebels Mediation Model###
################################################################
set.seed(23456)
med.out3 <- mediate(med.fit, out.fit, treat = "Non_military_Sanctions_N.D._Rebel", mediator = "lnvacTplus1",
                    NeweyWest= TRUE, sims = 1000, dropobs = TRUE, conf.level=0.95)
summary(med.out3)

#Exponentiated Coefficient
exp(0.2721)

#by increasing armed actors’ use of violence against civilians, an imposed economic sanction against rebels
#corresponds to an increase in refugee flows by an average of 31 percent

##################################################
###Figure 2: Economic Sanctions Mediation Model###
##################################################
plot(med.out3, xlab="Effect size",main="Economic Sanctions Against Rebels, 
     Violence Against Civilians, and Refugee Flows")
dev.off()




##############################
##############################
##############################
###Sanctions Against States###
##############################
##############################
##############################

#######################################
###STATE Mediator and Outcome Models###
#######################################
rm(list=ls())
load("FPA.Rdata")

#Mediator Model: Sanctions against the state
med.fit <- lm(lnvacTplus1 ~ 
                Military_Sanctions_State+Non_military_Sanctions_N.D._State+v2x_api+lnTotal+
                lngdppc+ logpop+gd_ptsa
              , data=omit)
coeftest(med.fit, vcov.=NeweyWest(med.fit, adjust=TRUE, verbose=TRUE)) 

#Outcome model: Sanctions against the state
out.fit <- lm(logrefugeeTplus1 ~ 
                Military_Sanctions_State+Non_military_Sanctions_N.D._State+v2x_api+lnvacTplus1+lnTotal+
                lngdppc + logpop+inter+gd_ptsa
              , data=omit)
coeftest(out.fit, vcov.=NeweyWest(out.fit, adjust=TRUE, verbose=TRUE)) 

################################################################
###Model 7: Military Sanctions Against States Mediation Model###
################################################################
set.seed(23456)
med.out6 <- mediate(med.fit, out.fit, treat = "Military_Sanctions_State", mediator = "lnvacTplus1",
                    NeweyWest= TRUE, sims = 1000, dropobs = TRUE, conf.level=0.95)
summary(med.out6)

#Exponentiated Coefficient
1-exp(-0.125)

#by reducing violence against civilians caused by armed actors, an imposed military sanction against states
#corresponds to a decrease in the flow of refugees by about 12 percent. 

##################################################
###Figure 3: Military Sanctions Mediation Model###
##################################################
plot(med.out6, xlab="Effect size",main="Military Sanctions Against the State, 
     Violence Against Civilians, and Refugee Flows")
dev.off()

################################################################
###Model 8: Economic Sanctions Against States Mediation Model###
################################################################
set.seed(23456)
med.out5 <- mediate(med.fit, out.fit, treat = "Non_military_Sanctions_N.D._State", mediator = "lnvacTplus1",
                    NeweyWest= TRUE, sims = 1000, dropobs = TRUE, conf.level=0.95)
summary(med.out5)

#Exponentiated Coefficient
exp(0.2321)

#by increasing armed actors’ use of violence against civilians, an imposed economic sanction against states
#corresponds to an increase in refugee flows by an average of 26 percent

##################################################
###Figure 3: Economic Sanctions Mediation Model###
##################################################
plot(med.out5, xlab="Effect size",main="Economic Sanctions Against the State, 
     Violence Against Civilians, and Refugee Flows")
dev.off()